<template>
	<view class="personalInfo  ">

		<view class="personalBox bgWhite radius8">
			<uv-form labelPosition="left" :model="personaModel" :rules="personalRules" :labelStyle="labelStyle"
				ref="form">
				<uv-form-item label="公司名称" borderBottom labelWidth="140rpx">
					<uv-input :disabled="type==2" inputAlign="right" v-model="personaModel.title" border="none"
						placeholder="请输入">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="营业执照编号" borderBottom labelWidth="200rpx">
					<uv-input :disabled="type==2" inputAlign="right" v-model="personaModel.shopcode" border="none"
						placeholder="请输入">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="联系人" borderBottom labelWidth="140rpx">
					<uv-input inputAlign="right" v-model="personaModel.name" border="none" placeholder="请输入">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="联系人手机号" borderBottom labelWidth="220rpx">
					<uv-input inputAlign="right" v-model="personaModel.faren_mobile" border="none" placeholder="请输入">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="联系人身份证号" borderBottom labelWidth="220rpx">
					<uv-input inputAlign="right" v-model="personaModel.idcode" border="none" placeholder="请输入">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="地址" borderBottom labelWidth="140rpx">
					<uv-input inputAlign="right" v-model="personaModel.address" border="none" placeholder="请输入">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="公司法人" borderBottom labelWidth="140rpx">
					<uv-input inputAlign="right" v-model="personaModel.faren_name" border="none" placeholder="请输入">
					</uv-input>
				</uv-form-item>
			
				<uv-form-item label="法人身份证号" borderBottom labelWidth="200rpx">
					<uv-input inputAlign="right" v-model="personaModel.faren_code" border="none" placeholder="请输入">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="公司行业" borderBottom labelWidth="180rpx">
					<uv-input inputAlign="right" v-model="personaModel.hangye" border="none"
						placeholder="例如房产、食品、医药等行业">
					</uv-input>
				</uv-form-item>
			</uv-form>
		</view>
		<view class="personalBox bgWhite radius8 mt12">
			<uv-form-item label="上传联系人身份证" labelPosition="top" labelWidth="220rpx">
				<view class="justify-between align-center mt15">
					<view class="posRelative " @click="upload(1)">
						<image v-if="personaModel.sfz1" :src="personaModel.sfz1" mode=""></image>
						<image v-else src="../../static/images/1.jpg" class="radius5" mode="widthFix"></image>
						<view class="posAbsort textbox">
							上传身份证正面照片
						</view>
					</view>
					<view class="posRelative " @click="upload(2)">
						<image v-if="personaModel.sfz2" :src="personaModel.sfz2" mode=""></image>
						<image v-else src="../../static/images/2.jpg" class="radius5" mode="widthFix"></image>
						<view class="posAbsort textbox">
							上传身份证反面照片
						</view>
					</view>
				</view>
			</uv-form-item>
			<view class="">
				<view class="moneydesc">
					上传公司合法文件
				</view>
				<view class="align-center flex-wrap justify-start">
					<view class="mr10 mt5 posRelative" v-for="(i,n) in imgList" :key="n">
						<image style="width: 180rpx;height: 180rpx;border-radius: 15rpx;" :src="i" mode=""></image>
						<view v-if="type!='2'" @click="del(n)" class="posAbsort" style="right: 10rpx;top: 10rpx">
							<uv-icon name="close-circle"></uv-icon>
						</view>
					</view>
				</view>

				<view v-if="imgList.length<6" class="plus align-center justify-center" @click="upload(3)">
					<uv-icon color="#B0B0B0" size="25" name="plus"></uv-icon>
				</view>
			</view>
		</view>
		<!-- <view v-if="type!='1'" class="xy align-center justify-center">
			<uv-checkbox-group v-model="checked" @change="changeCheck">
				<uv-checkbox shape="circle" activeColor="#49806F" name="apple" label="">
					<template #default>
						<view class="align-center justify-center ft13" style="color: #999;">
							阅读并签署<text @click.stop="toxy(2)" style="color: #49806F;">《网签合同》</text>
						</view>
					</template>
				</uv-checkbox>
			</uv-checkbox-group>
		</view> -->
		<view class="save_btn" @click="save">
			提交
		</view>

		<uv-popup ref="modal" :bgColor="none" :showConfirmButton="false">
			<view class="successBox align-center justify-center flex-col">
				<image src="../../static/images/success.png" mode="widthFix"></image>
				<view class="success">
					注册成功
				</view>
				<view class="desc">
					请阅读并签署<text style="color: #49806F;">《供应商合同》</text>协议
				</view>
				<view class="confirm" @click="toxy">
					去签署
				</view>
			</view>
		</uv-popup>
		<uv-picker ref="areaPicker" :columns="areaRrand" keyName="name" @change="carChange"
			@confirm="areaConfirm"></uv-picker>
	</view>
</template>

<script>
	import operate from '@/common/operate.js'
	export default {
		data() {
			return {
				labelStyle: {
					'height': '87rpx',
					'font-size': "30rpx",
					'color': '#000'
				},
				personaModel: {
					shopcode: "",
					// hezuo: "",
					address: "",
					yingye: "",
					sfz1: "",
					sfz2: "",
					name: "",
					mobile: "",
					title: "",
					faren_name: '',
					faren_code: "",
					faren_mobile: "",
					hangye: ""

				},
				personalRules: {},
				checked: [],
				loading: false,
				signed: false,
				type: "",
				imgList: []
			};
		},

		onLoad(opt) {
			if (opt.type) this.type = opt.type
			this.signed = false
			this.$api.gongyingshanginfo().then(res => {
				console.log(res)
				if (res.data) {
					this.personaModel = res.data
					this.imgList = res.data.yingye.split(',')
				}

				// this.imgList=res.data.yingye.split(',')
			})
		},
		mounted() {
			let vm = this
			uni.$on('signSuccess', function() {
				vm.$refs.modal.close()
				vm.$utils.msg('签署成功')
				setTimeout(() => {
					uni.switchTab({
						url: '/pages/tabbar/mine'
					})
				}, 500)
			})
		},
		onBackPress() {
			uni.switchTab({
				url: '/pages/tabbar/mine'
			})
			return true
		},
		methods: {
			changeCheck(val) {
				this.checked = val
			},
			del(n) {
				this.imgList.splice(n, 1)
			},
			upload(type) {
				let vm = this
				if (this.type == 2) return
				uni.chooseImage({
					sourceType: ['album'],
					count: type == 3 ? 6 - vm.imgList.length : 1,
					success: function(res) {
						console.log(res)
						res.tempFilePaths.map(item => {
							vm.$api.uploadImg({
								filePath:item
							}).then(res => {
								switch (type) {
									case 1:
										vm.personaModel.sfz1 = res.data.fullurl
										break;
									case 2:
										vm.personaModel.sfz2 = res.data.fullurl
										break;
									case 3:
										vm.imgList.push(res.data.fullurl)
										break;
								}
							})
						})
					}
				})
			},
			async save() {
				let vm = this
				if (!vm.personaModel.title) return vm.$utils.msg('请输入公司名称')
				if (!vm.personaModel.shopcode) return vm.$utils.msg('请输入营业执照编号')
				if (!vm.personaModel.name) return vm.$utils.msg('请输入联系人')
				if (!vm.personaModel.idcode) return vm.$utils.msg('请输入身份证号')
				if (!vm.personaModel.address) return vm.$utils.msg('请输入地址')
				if (!vm.personaModel.faren_name) return vm.$utils.msg('请输入公司法人姓名')
				if (!vm.personaModel.faren_mobile) return vm.$utils.msg('请输入公司法人手机号')
				if (!vm.personaModel.faren_code) return vm.$utils.msg('请输入公司法人身份证号')
				if (!vm.personaModel.hangye) return vm.$utils.msg('请输入公司行业')
				if (!vm.personaModel.sfz1) return vm.$utils.msg('请上传身份证正面图片')
				if (!vm.personaModel.sfz2) return vm.$utils.msg('请上传身份证反面图片')
				if (!vm.imgList.length) return vm.$utils.msg('请上传营业执照')
				vm.personaModel.yingye = vm.imgList.join(',')
				// if(!this.signed&&!vm.personaModel.id) return vm.$utils.msg('请阅读并签署线上协议')

				if (vm.loading) return
				vm.loading = true
				uni.showLoading({})
				vm.$api.addgongyingshang(vm.personaModel).then(res => {
					uni.hideLoading()
					vm.loading = false
					if (res.code == 1) {

						setTimeout(() => {
							// vm.toxy()
						}, 800)

						if (!vm.personaModel.dianzihetong) {
							vm.$refs.modal.open()
						} else {
							this.$utils.msg('修改成功')

							setTimeout(() => {
								uni.navigateBack()
							}, 800)
						}


					} else {
						vm.$utils.msg(res.msg)
					}
				})
			},
			toindex() {
				uni.switchTab({
					url: '/pages/tabbar/mine'
				})
			},
			toxy() {
				uni.navigateTo({
					url: `/pages/signAbout/index?type=2&title=${this.personaModel.title}&name=${this.personaModel.name}&sfz=${this.personaModel.idcode}&zhusuo=${this.personaModel.address}`
				})
				// uni.navigateTo({
				// 	url: '/pages/signAbout/index?type=2'
				// })
			}
		}
	}
</script>
<style>
	page {
		background-color: #f5f5f5;
	}
</style>
<style lang="scss" scoped>
	.header {
		margin-top: 52rpx;
		margin-bottom: 40rpx;
		font-weight: 600;
		font-size: 36rpx;
		color: #000000;
		line-height: 36rpx;

	}

	.personalInfo {

		padding: 22rpx;
		position: relative;

		.personalBox {
			padding: 0 32rpx 40rpx;

		}

		.save_btn {
			width: 100%;
			height: 90rpx;
			margin-top: 38rpx;
			margin-bottom: 40rpx;
			background: #49806F;
			border-radius: 12rpx;
			font-size: 32rpx;
			color: #FFFFFF;
			text-align: center;
			line-height: 90rpx;
		}

	}

	button {
		color: #303133;
		font-size: 28rpx;
		text-align: left;
	}

	image {
		width: 300rpx;
		border-radius: 12rpx;
		height: 200rpx;

	}

	.textbox {
		width: 300rpx;
		height: 51rpx;
		background: #DFC199;
		border-radius: 0 0 10rpx 10rpx;
		font-weight: 400;
		font-size: 23rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 51rpx;
		bottom: 0;
		left: 0;
	}

	.plus {
		width: 200rpx;
		height: 200rpx;
		background: #F5F5F7;
		border-radius: 15rpx;
	}

	.moneydesc {
		font-size: 30rpx;
		color: #333;
		margin: 50rpx 0 26rpx;

		text {
			font-size: 22rpx;
			color: #999999
		}
	}

	.xy {
		margin-top: 40rpx;

		text {}
	}

	.successBox {
		width: 631rpx;
		height: 500rpx;
		background: linear-gradient(0deg, #D2E6C4, #7AB588);
		border-radius: 28rpx;
		font-size: 32rpx;
		color: #111111;

		image {
			width: 120rpx;
		}

		.success {
			font-weight: bold;

			margin: 38rpx 0;
		}

		.confirm {
			width: 193rpx;
			height: 72rpx;
			background: linear-gradient(0deg, #BEDDB5, #7FB98C);
			box-shadow: 0rpx 3rpx 7rpx 0rpx rgba(11, 26, 20, 0.35);
			border-radius: 36rpx;
			color: #003E22;
			font-weight: bold;
			margin-top: 50rpx;
			line-height: 72rpx;
			text-align: center;

		}
	}
</style>